package io.iec.edp.caf.data.source.gauss;

import io.iec.edp.caf.data.source.RelationalServiceInfo;
import io.iec.edp.caf.data.source.pgsql.PostgresqlServiceInfo;

/**
 * GaussDB的pg模式，几乎和pg一模一样，所以以pg作为基类处理个性化设置
 */
public class GaussDB4PgServiceInfo extends PostgresqlServiceInfo {
    public GaussDB4PgServiceInfo(String uriString) {
        super(uriString);
    }

    public GaussDB4PgServiceInfo(String host, int port, String username, String password, String path, String query) {
        super(host, port, username, password, path, query);
    }

    public GaussDB4PgServiceInfo(String jdbcUrl, String userName, String password) {
        super(jdbcUrl, userName, password);
    }

    /**
     * 高斯数据库url使用的schema是postgresql
     * @return
     */
    @Override
    protected String buildJdbcUrl() {
        return String.format("%s%s://%s%s/%s%s", JDBC_PREFIX, POSTGRES_SCHEME, getHost(), formatPort(),
                getPath(),formatQuery());
    }

    @Override
    protected String formatQuery() {
        if (getQuery() != null) {
            return String.format("?extensionType=GaussDB%s", getQuery());
        }
        return "";
    }

    /**
     * 获取驱动类名
     * @return
     */
    @Override
    public String getDriverClassName(){
        return POSTGRES_DRIVER_CLASS_NAME;
    }
}
